﻿using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using Extensions;
using System;

namespace Tailord
{
    public partial class TedarikMailAdresleri : XForm
    {
        public TedarikMailAdresleri()
        {
            InitializeComponent();
        }

        private void TedarikMailAdresleri_Load(object sender, EventArgs e)
        {
            ShowOnlyBar();

            gvMail.Init("GetTedarikMail");

            gvMail.MakeColumnInvisible("TedarikMailId");

            RepositoryItemGridLookUpEdit gleSenderType = GetCustomRI("SenderType", false, "To", "Cc");
            gvMail.Columns["SenderType"].ColumnEdit = gleSenderType;

            RepositoryItemGridLookUpEdit gleTedarikYeri = GetCustomRI("TedarikYeri", false, "SÖKTAŞ", "TAILORD", "AKFİL","DESTEX","ALBINI");
            gvMail.Columns["TedarikYeri"].ColumnEdit = gleTedarikYeri;

            gvMail.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;


            gvMail.BestFitColumns();

            bbiSave.ItemClick += bbiSave_ItemClick;
        }

        void bbiSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            EndGridViewEdit(gvMail);

            bool eksikBilgi = gvMail.DataTable().Select("Isnull(Mail,'')='' or Isnull(SenderType,'')='' ").Length > 0;

            if (eksikBilgi)
            {
                XtraMessageBox.Show("Mail ya da SenderType alanlarını boş bırakamazsınız !");
                    return;
            }

            gvMail.Update("TedarikMailId, TedarikYeri, Mail, SenderType", "TedarikMail");
        }
    }
}